package com.koko.controller;

import com.koko.game.vo.GameCartVO;
import com.koko.order.entity.Cart;
import com.koko.order.vo.CartGameVO;
import com.koko.result.Result;
import com.koko.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class CartController {
    @Autowired
    private CartService cartService;

    /**
     * 向购物车中添加游戏
     * @param cart
     * @return
     */
    @PostMapping("/cart")
    public Result<String> addToCart(@RequestBody Cart cart) {
        cartService.addGameToUserCart(cart.getGameId());
        return Result.success();
    }

    /**
     * 获取购物车中的数据
     * @return
     */
    @GetMapping("/cart/all")
    public Result<List<CartGameVO>> getAllGames() {
        List<CartGameVO> list = cartService.getAllGames();
        return Result.success(list);
    }

    @DeleteMapping("/cart")
    public Result<String> deleteById(@RequestBody List<Long> ids) {
        cartService.deleteById(ids);
        return Result.success();
    }
}
